﻿#include "function.h"
#include <para.h>
extern MyPARA my_para;
Function::Function(QDialog* parent, QString dir, int camera_index) : QDialog(parent)
{

	m_camera_index = camera_index;
    m_section = "common";

	m_dir = dir;
	



    QString path = dir +"/vision_para/" + my_para.m_vector_camera_name[m_camera_index]+ ".ini";
    m_qsettings = new QSettings(path, QSettings::IniFormat);


    this->setWindowTitle("para");
    QRect desktop_rect = QApplication::desktop()->geometry();
    double ratio_x = desktop_rect.width() / 1920.0;
    double ratio_y = desktop_rect.height() / 1080.0;

    move(0, 0);
    setFixedSize(1920 * ratio_x, 1010 * ratio_y);



    pixmapItem = new QGraphicsPixmapItem();

    m_listview = new QListView(this);
    m_listview->setSelectionBehavior(QAbstractItemView::SelectRows);	// 设置选择行为时每次选择一行
    m_listview->setEditTriggers(QAbstractItemView::NoEditTriggers);		// 设置不可编辑
    //m_listview->setStyleSheet("selection-background-color:lightblue;");	// 设置选中背景色
    m_listview->setGeometry(500 * ratio_x, 0, 150*ratio_x, 800 * 1.2 * ratio_y);
    m_listview_model = new QStringListModel();
    m_listview->setModel(m_listview_model);
    connect(m_listview, &QListView::clicked, this, &Function::listViewClick);

    m_view = new QtQGraphicsView(this);
	m_view->setGeometry(660 * ratio_x, 0, 1250 * ratio_x, 940 * ratio_y);

   

    QWidget* p = new QWidget(this);
    p->move(0 * ratio_x, 0 * ratio_y);
    p->setFixedSize(500 * ratio_x, 800 * ratio_y);

    QGridLayout* qgridLayout = new QGridLayout();
    p->setLayout(qgridLayout);

    int index = 0;

    QSize control_size(220 * ratio_x, 40 * ratio_y);

    m_pushbutton_load_image = new QPushButton(this);
    m_pushbutton_load_image->setText("Load One Image");
    m_pushbutton_load_image->setFixedSize(control_size);
    connect(m_pushbutton_load_image, &QPushButton::clicked, this, [=]() {
        QString filename;
        filename = QFileDialog::getOpenFileName(this,
            tr("select image"),
            "",
            tr("Images (*.png *.bmp *.jpg)"));
        if (filename.isEmpty())
        {
            return;
        }

        m_image = imread(filename.toLocal8Bit().toStdString(), IMREAD_UNCHANGED);
		m_listview_model->removeRows(0, m_listview_model->rowCount());


        if (m_image.empty())
        {
            QMessageBox::information(nullptr, "", "load image error");
            return;
        }


        QImage q_image = matToQImage(m_image);
        m_view->setImage(q_image, "");
        });
    qgridLayout->addWidget(m_pushbutton_load_image, index, 0);

    m_pushbutton_load_dir = new QPushButton(this);
    m_pushbutton_load_dir->setText("load Images Dir");
    m_pushbutton_load_dir->setFixedSize(control_size);
    connect(m_pushbutton_load_dir, &QPushButton::clicked, this, [=]() {
        QString directory;

        directory = QFileDialog::getExistingDirectory(this,
            tr("select dir"),
            "");
        if (directory.isEmpty())
        {
            return;
        }

        QDir dir(directory);
        dir.setFilter(QDir::Files | QDir::NoSymLinks);
        QStringList filters;
        filters << "*.bmp" << "*.jpg" << "*.png";
        dir.setNameFilters(filters);



        QStringList  string_list = dir.entryList();
        QStringList string_list_path;
        foreach(QString  var, string_list) {
            string_list_path << directory + "/" + var;
        }

        m_listview_model->setStringList(string_list_path);
        });

    qgridLayout->addWidget(m_pushbutton_load_dir, index, 1);
    index++;

	if (camera_index == 3)
	{
        m_function_circle = new FunctionCircleMatch(this, m_qsettings, "m_function_circle");

		m_pushbutton_circle = new QPushButton(this);
		m_pushbutton_circle->setFixedSize(control_size);
		m_pushbutton_circle->setText("Circle");
		connect(m_pushbutton_circle, &QPushButton::clicked, this, [=]() {

			if (m_unuse_use_circle == 0)
            {
				QMessageBox::critical(nullptr, "circle", "OFF");
				return;
			}
			if (m_image.empty())
			{
				QMessageBox::information(nullptr, "", "no image");
				return;
			}
			QString message;
			m_function_circle->m_image = m_image;
			m_function_circle->showDialog();
			m_function_circle->show();
		});
		qgridLayout->addWidget(m_pushbutton_circle, index, 0);

		m_qcombobox_unuse_use_circle = new QComboBox(this);
		m_qcombobox_unuse_use_circle->setFixedSize(control_size);
		m_qcombobox_unuse_use_circle->addItem("OFF");
		m_qcombobox_unuse_use_circle->addItem("ON");
		m_qcombobox_unuse_use_circle->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
		connect(m_qcombobox_unuse_use_circle, &QComboBox::currentTextChanged, this, [=]() {
			if (m_qcombobox_unuse_use_circle->currentIndex() == 0)
			{
				m_qcombobox_unuse_use_circle->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			}
			else
			{
				m_qcombobox_unuse_use_circle->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
			}
		});
		qgridLayout->addWidget(m_qcombobox_unuse_use_circle, index, 1);

		index++;
	}

    if (camera_index == 10)
    {
        m_function_find_shape_model = new FunctionFindShapeModel(this,m_qsettings, "m_function_find_shape_model",dir);

        m_pushbutton_find_shape_model = new QPushButton(this);
        m_pushbutton_find_shape_model->setFixedSize(control_size);
        m_pushbutton_find_shape_model->setText("Match");
        connect(m_pushbutton_find_shape_model, &QPushButton::clicked, this, [=]() {

            if (m_unuse_use_find_shape_model == 0)
            {
                QMessageBox::critical(nullptr, "Match", "OFF");
                return;
            }
            if (m_image.empty())
            {
                QMessageBox::information(nullptr, "", "no image");
                return;
            }
            QString message;
            m_function_find_shape_model->m_image = m_image;
            m_function_find_shape_model->showDialog();
            m_function_find_shape_model->show();
        });
        qgridLayout->addWidget(m_pushbutton_find_shape_model, index, 0);

        m_qcombobox_unuse_use_find_shape_model = new QComboBox(this);
        m_qcombobox_unuse_use_find_shape_model->setFixedSize(control_size);
        m_qcombobox_unuse_use_find_shape_model->addItem("OFF");
        m_qcombobox_unuse_use_find_shape_model->addItem("ON");
		m_qcombobox_unuse_use_find_shape_model->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
		connect(m_qcombobox_unuse_use_find_shape_model, &QComboBox::currentTextChanged, this, [=]() {
			if (m_qcombobox_unuse_use_find_shape_model->currentIndex() == 0)
			{
				m_qcombobox_unuse_use_find_shape_model->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			}
			else
			{
				m_qcombobox_unuse_use_find_shape_model->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
			}
		});

        qgridLayout->addWidget(m_qcombobox_unuse_use_find_shape_model, index, 1);

        index++;
    }

	if (camera_index == 3 || camera_index == 4)
	{
		m_dl_times = 3;
	}

	if (camera_index == 3)
	{
		m_vector_segment_rect.resize(m_dl_times);
		m_vector_pushbutton_segment_rect.resize(m_dl_times);
		m_vector_qcombobox_unuse_use_segment_rect.resize(m_dl_times);
		m_vector_unuse_use_segment_rect.resize(m_dl_times);
		for (int i = 0; i < m_dl_times; i++)
		{
			m_vector_segment_rect[i] = new FunctionSegmentRect(this, m_qsettings, "m_function_rect" + QString::number(i));

			m_vector_pushbutton_segment_rect[i] = new QPushButton(this);
			m_vector_pushbutton_segment_rect[i]->setFixedSize(control_size);
			m_vector_pushbutton_segment_rect[i]->setText("AI Segment Top" + QString::number(i));
			connect(m_vector_pushbutton_segment_rect[i], &QPushButton::clicked, this, [=]() {

				if (m_vector_unuse_use_segment_rect[i] == 0)
				{
					QMessageBox::critical(nullptr, "ai segment", "OFF");
					return;
				}
				if (m_image.empty())
				{
					QMessageBox::information(nullptr, "", "no image");
					return;
				}
				QString message;
				m_vector_segment_rect[i]->m_image = m_image;
				m_vector_segment_rect[i]->showDialog();
				m_vector_segment_rect[i]->show();
			});
			qgridLayout->addWidget(m_vector_pushbutton_segment_rect[i], index, 0);

			m_vector_qcombobox_unuse_use_segment_rect[i] = new QComboBox(this);
			m_vector_qcombobox_unuse_use_segment_rect[i]->setFixedSize(control_size);
			m_vector_qcombobox_unuse_use_segment_rect[i]->addItem(QString::number(i) + "OFF");
			m_vector_qcombobox_unuse_use_segment_rect[i]->addItem(QString::number(i) + "ON");
			m_vector_qcombobox_unuse_use_segment_rect[i]->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			connect(m_vector_qcombobox_unuse_use_segment_rect[i], &QComboBox::currentTextChanged, this, [=]() {
				if (m_vector_qcombobox_unuse_use_segment_rect[i]->currentIndex() == 0)
				{
					m_vector_qcombobox_unuse_use_segment_rect[i]->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
				}
				else
				{
					m_vector_qcombobox_unuse_use_segment_rect[i]->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
				}
			});
			qgridLayout->addWidget(m_vector_qcombobox_unuse_use_segment_rect[i], index, 1);

			index++;
		}
	}

    if (camera_index == 4)
    {
        m_vector_segment_circle.resize(m_dl_times);
        m_vector_pushbutton_segment_circle.resize(m_dl_times);
        m_vector_qcombobox_unuse_use_segment_circle.resize(m_dl_times);
        m_vector_unuse_use_segment_circle.resize(m_dl_times);
        for(int i=0;i<m_dl_times;i++)
        {
            m_vector_segment_circle[i] = new FunctionSegmentCircle(this, m_qsettings, "m_function_circle" + QString::number(i));

            m_vector_pushbutton_segment_circle[i] = new QPushButton(this);
            m_vector_pushbutton_segment_circle[i]->setFixedSize(control_size);
            m_vector_pushbutton_segment_circle[i]->setText("AI Segment"+QString::number(i));
            connect(m_vector_pushbutton_segment_circle[i], &QPushButton::clicked, this, [=]() {

                if (m_vector_unuse_use_segment_circle[i] == 0)
                {
                    QMessageBox::critical(nullptr, "ai segment", "OFF");
                    return;
                }
                if (m_image.empty())
                {
                    QMessageBox::information(nullptr, "", "no image");
                    return;
                }
                QString message;
                m_vector_segment_circle[i]->m_image = m_image;
                m_vector_segment_circle[i]->showDialog();
                m_vector_segment_circle[i]->show();
            });
            qgridLayout->addWidget(m_vector_pushbutton_segment_circle[i], index, 0);

            m_vector_qcombobox_unuse_use_segment_circle[i] = new QComboBox(this);
            m_vector_qcombobox_unuse_use_segment_circle[i]->setFixedSize(control_size);
            m_vector_qcombobox_unuse_use_segment_circle[i]->addItem(QString::number(i)+"OFF");
            m_vector_qcombobox_unuse_use_segment_circle[i]->addItem(QString::number(i)+"ON");
			m_vector_qcombobox_unuse_use_segment_circle[i]->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			connect(m_vector_qcombobox_unuse_use_segment_circle[i], &QComboBox::currentTextChanged, this, [=]() {
				if (m_vector_qcombobox_unuse_use_segment_circle[i]->currentIndex() == 0)
				{
					m_vector_qcombobox_unuse_use_segment_circle[i]->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
				}
				else
				{
					m_vector_qcombobox_unuse_use_segment_circle[i]->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
				}
			});
            qgridLayout->addWidget(m_vector_qcombobox_unuse_use_segment_circle[i], index, 1);

            index++;
        }
    }
    

    if (camera_index == 0 || camera_index == 1 || camera_index == 2)
    {
        m_function_segment_sacn = new FunctionSegmentScan(this,m_qsettings, "m_function_segment_sacn ");

        m_pushbutton_segment_sacn = new QPushButton(this);
        m_pushbutton_segment_sacn->setFixedSize(control_size);
        m_pushbutton_segment_sacn->setText("SegmentScan");
        connect(m_pushbutton_segment_sacn, &QPushButton::clicked, this, [=]() {

            if (m_unuse_use_segment_sacn == 0)
            {
                QMessageBox::critical(nullptr, "m_function_segment_sacn", "OFF");
                return;
            }
            if (m_image.empty())
            {
                QMessageBox::information(nullptr, "", "no image");
                return;
            }
            QString message;
            m_function_segment_sacn->m_image = m_image;
            m_function_segment_sacn->showDialog();
            m_function_segment_sacn->show();
        });
        qgridLayout->addWidget(m_pushbutton_segment_sacn, index, 0);

        m_qcombobox_unuse_use_segment_sacn = new QComboBox(this);
        m_qcombobox_unuse_use_segment_sacn->setFixedSize(control_size);
        m_qcombobox_unuse_use_segment_sacn->addItem("OFF");
        m_qcombobox_unuse_use_segment_sacn->addItem("ON");
        m_qcombobox_unuse_use_segment_sacn->setStyleSheet(R"(
                QComboBox {
                    background-color: red;
                    color: white;
                    border: 1px solid red;
                    border-radius: 3px;
                }
                )");
        connect(m_qcombobox_unuse_use_segment_sacn, &QComboBox::currentTextChanged, this, [=]() {
            if (m_qcombobox_unuse_use_segment_sacn->currentIndex() == 0)
            {
                m_qcombobox_unuse_use_segment_sacn->setStyleSheet(R"(
                QComboBox {
                    background-color: red;
                    color: white;
                    border: 1px solid red;
                    border-radius: 3px;
                }
                )");
            }
            else
            {
                m_qcombobox_unuse_use_segment_sacn->setStyleSheet(R"(
                QComboBox {
                    background-color: green;
                    color: white;
                    border: 1px solid green;
                    border-radius: 3px;
                }
                )");
            }
        });

        qgridLayout->addWidget(m_qcombobox_unuse_use_segment_sacn, index, 1);

        index++;
    }




    m_vector_dl_halcon.resize(m_dl_times);
    m_vector_pushbutton_dl_halcon.resize(m_dl_times);
    m_vector_qcombobox_unuse_use_dl_halcon.resize(m_dl_times);
    m_vector_unuse_use_dl_halcon.resize(m_dl_times);


    for(int i=0;i<m_dl_times;i++)
    {
        m_vector_pushbutton_dl_halcon[i] = new QPushButton(this);
        m_vector_pushbutton_dl_halcon[i]->setFixedSize(control_size);
        m_vector_pushbutton_dl_halcon[i]->setText("Deep Learimg"+QString::number(i));
        connect(m_vector_pushbutton_dl_halcon[i], &QPushButton::clicked, this, [=]() {
            if(m_vector_dl_halcon[i] == nullptr || m_vector_unuse_use_dl_halcon[i]==0)
            {
                 QMessageBox::critical(nullptr, "deep learimg new"+QString::number(i),"deep learimg no start");
                 return;
            }
            if (m_image.empty())
            {
                QMessageBox::information(nullptr, "", "no image");
                return;
            }
            if (m_vector_unuse_use_segment_circle.size() > i) {
                if (m_vector_unuse_use_segment_circle[i] == 1)
                {
                    QString message;
                    HObject image_in = matToHImage(m_image);
                    m_vector_segment_circle[i]->detection(image_in, message);
                    m_vector_dl_halcon[i]->m_image = himageToMat(m_vector_segment_circle[i]->image_crop);
                    m_vector_dl_halcon[i]->show();
                    m_vector_dl_halcon[i]->showDialog();
                    return;
                }
            }
            if (m_vector_unuse_use_segment_rect.size() > i) {
                if (m_vector_unuse_use_segment_rect[i] == 1)
                {
                    QString message;
                    HObject image_in = matToHImage(m_image);
                    m_vector_segment_rect[i]->detection(image_in, message);
                    m_vector_dl_halcon[i]->m_image = himageToMat(m_vector_segment_rect[i]->image_crop);
                    m_vector_dl_halcon[i]->show();
                    m_vector_dl_halcon[i]->showDialog();
                    return;
                }
            }

            if(m_function_segment_sacn!=nullptr)
            {
                QString message;
                HObject image_in = matToHImage(m_image);
                m_function_segment_sacn->detection(image_in, message);
                m_vector_dl_halcon[i]->m_image = himageToMat(m_function_segment_sacn->image_crop);
                m_vector_dl_halcon[i]->show();
                m_vector_dl_halcon[i]->showDialog();
                return;
            }
            m_vector_dl_halcon[i]->m_image = m_image;
            m_vector_dl_halcon[i]->show();
            m_vector_dl_halcon[i]->showDialog();

        });
        qgridLayout->addWidget(m_vector_pushbutton_dl_halcon[i], index, 0);
        m_vector_pushbutton_dl_halcon.push_back(m_vector_pushbutton_dl_halcon[i]);

        m_vector_qcombobox_unuse_use_dl_halcon[i] = new QComboBox(this);
        m_vector_qcombobox_unuse_use_dl_halcon[i]->setFixedSize(control_size);
        m_vector_qcombobox_unuse_use_dl_halcon[i]->addItem(QString::number(i)+"OFF");
        m_vector_qcombobox_unuse_use_dl_halcon[i]->addItem(QString::number(i)+"ON");
        m_vector_qcombobox_unuse_use_dl_halcon[i]->setStyleSheet(R"(
                QComboBox {
                    background-color: red;
                    color: white;
                    border: 1px solid red;
                    border-radius: 3px;
                }
                )");
        connect(m_vector_qcombobox_unuse_use_dl_halcon[i], &QComboBox::currentTextChanged, this, [=]() {
            if (m_vector_qcombobox_unuse_use_dl_halcon[i]->currentIndex() == 0)
            {
                m_vector_qcombobox_unuse_use_dl_halcon[i]->setStyleSheet(R"(
                QComboBox {
                    background-color: red;
                    color: white;
                    border: 1px solid red;
                    border-radius: 3px;
                }
                )");
            }
            else
            {
                m_vector_qcombobox_unuse_use_dl_halcon[i]->setStyleSheet(R"(
                QComboBox {
                    background-color: green;
                    color: white;
                    border: 1px solid green;
                    border-radius: 3px;
                }
                )");
            }
        });
        qgridLayout->addWidget(m_vector_qcombobox_unuse_use_dl_halcon[i], index, 1);
        index++;
    }








    if(camera_index==0 || camera_index==1)
    {
		m_function_dump = new FunctionDump(this, m_qsettings, "m_function_dump", camera_index);

		if (camera_index == 0)
		{
			m_function_dump->m_positon = 1;
			m_function_dump->m_transition = 0;
		}
		if (camera_index == 1)
		{
			m_function_dump->m_positon = 0;
			m_function_dump->m_transition = 1;
		}

        m_pushbutton_dump = new QPushButton(this);
        m_pushbutton_dump->setFixedSize(control_size);
        m_pushbutton_dump->setText("Dump");
        connect(m_pushbutton_dump, &QPushButton::clicked, this, [=]() {

                if(m_unuse_use_dump==0)
                {
                     QMessageBox::critical(nullptr, "Dump","OFF");
                     return;
                }
				if (m_image.empty())
				{
					QMessageBox::information(nullptr, "", "no image");
					return;
				}
                QString message;
                m_function_dump->m_image = m_image;
                m_function_dump->showDialog();
                m_function_dump->show();
                   });
         qgridLayout->addWidget(m_pushbutton_dump, index, 0);

         m_qcombobox_unuse_use_dump = new QComboBox(this);
         m_qcombobox_unuse_use_dump->setFixedSize(control_size);
         m_qcombobox_unuse_use_dump->addItem("OFF");
         m_qcombobox_unuse_use_dump->addItem("ON");
		 m_qcombobox_unuse_use_dump->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
		 connect(m_qcombobox_unuse_use_dump, &QComboBox::currentTextChanged, this, [=]() {
			 if (m_qcombobox_unuse_use_dump->currentIndex() == 0)
			 {
				m_qcombobox_unuse_use_dump->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			 }
			 else
			 {
				m_qcombobox_unuse_use_dump->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
			 }
		 });
         qgridLayout->addWidget(m_qcombobox_unuse_use_dump, index, 1);

        index++;
    }

    if (camera_index==0 || camera_index==1)
	{
		m_function_width_measure = new FunctionWidthMeasure(this, m_qsettings, "m_function_width_measure");
		m_pushbutton_width_measure = new QPushButton(this);
		m_pushbutton_width_measure->setFixedSize(control_size);
		m_pushbutton_width_measure->setText("Width Measure");
		connect(m_pushbutton_width_measure, &QPushButton::clicked, this, [=]() {

			if (m_unuse_use_width_measure == 0)
			{
				QMessageBox::critical(nullptr, "width measure", "OFF");
				return;
			}
			if (m_image.empty())
			{
				QMessageBox::information(nullptr, "", "no image");
				return;
			}
			QString message;
			m_function_width_measure->m_image = m_image;
			m_function_width_measure->showDialog();
			m_function_width_measure->show();
		});
		qgridLayout->addWidget(m_pushbutton_width_measure, index, 0);

		m_qcombobox_unuse_use_width_measure = new QComboBox(this);
		m_qcombobox_unuse_use_width_measure->setFixedSize(control_size);
		m_qcombobox_unuse_use_width_measure->addItem("OFF");
		m_qcombobox_unuse_use_width_measure->addItem("ON");
		m_qcombobox_unuse_use_width_measure->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
		connect(m_qcombobox_unuse_use_width_measure, &QComboBox::currentTextChanged, this, [=]() {
			if (m_qcombobox_unuse_use_width_measure->currentIndex() == 0)
			{
				m_qcombobox_unuse_use_width_measure->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			}
			else
			{
				m_qcombobox_unuse_use_width_measure->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
			}
		});
		qgridLayout->addWidget(m_qcombobox_unuse_use_width_measure, index, 1);

		index++;
	}

    if (camera_index == 2)
    {
        m_function_frank_width = new FunctionFrankWidth(this, m_qsettings, "m_function_frank_width");
        m_pushbutton_frank_width = new QPushButton(this);
        m_pushbutton_frank_width->setFixedSize(control_size);
        m_pushbutton_frank_width->setText("Flank Width");
        connect(m_pushbutton_frank_width, &QPushButton::clicked, this, [=]() {

            if (m_unuse_use_frank_width == 0)
            {
                QMessageBox::critical(nullptr, "width measure", "OFF");
                return;
            }
            if (m_image.empty())
            {
                QMessageBox::information(nullptr, "", "no image");
                return;
            }
            QString message;
            m_function_frank_width->m_image = m_image;
            m_function_frank_width->showDialog();
            m_function_frank_width->show();
        });
        qgridLayout->addWidget(m_pushbutton_frank_width, index, 0);

        m_qcombobox_unuse_use_frank_width = new QComboBox(this);
        m_qcombobox_unuse_use_frank_width->setFixedSize(control_size);
        m_qcombobox_unuse_use_frank_width->addItem("OFF");
        m_qcombobox_unuse_use_frank_width->addItem("ON");
		m_qcombobox_unuse_use_frank_width->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
		connect(m_qcombobox_unuse_use_frank_width, &QComboBox::currentTextChanged, this, [=]() {
			if (m_qcombobox_unuse_use_frank_width->currentIndex() == 0)
			{
				m_qcombobox_unuse_use_frank_width->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			}
			else
			{
				m_qcombobox_unuse_use_frank_width->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
			}
		});
        qgridLayout->addWidget(m_qcombobox_unuse_use_frank_width, index, 1);

        index++;
    }
	if (camera_index == 2)
	{

		m_function_frank_match = new DetectionFrankMatch(this, m_qsettings, "m_function_frank_match",dir);
		m_function_frank_match->m_image = m_image;

		m_pushbutton_frank_match = new QPushButton(this);
		m_pushbutton_frank_match->setFixedSize(control_size);
        m_pushbutton_frank_match->setText("Flank Match");
		connect(m_pushbutton_frank_match, &QPushButton::clicked, this, [=]() {

			if (m_unuse_use_frank_match == 0)
			{
                QMessageBox::critical(nullptr, "Flank Match", "OFF ");
				return;
			}
			if (m_image.empty())
			{
				QMessageBox::information(nullptr, "", "no image");
				return;
			}
			QString message;
			m_function_frank_match->m_image = m_image;
			m_function_frank_match->showDialog();
			m_function_frank_match->show();
		});
		qgridLayout->addWidget(m_pushbutton_frank_match, index, 0);

		m_qcombobox_unuse_use_frank_match = new QComboBox(this);
		m_qcombobox_unuse_use_frank_match->setFixedSize(control_size);
		m_qcombobox_unuse_use_frank_match->addItem("OFF");
		m_qcombobox_unuse_use_frank_match->addItem("ON");
		m_qcombobox_unuse_use_frank_match->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
		connect(m_qcombobox_unuse_use_frank_match, &QComboBox::currentTextChanged, this, [=]() {
			if (m_qcombobox_unuse_use_frank_match->currentIndex() == 0)
			{
				m_qcombobox_unuse_use_frank_match->setStyleSheet(R"(
		        QComboBox {
		            background-color: red;
		            color: white;
		            border: 1px solid red;
		            border-radius: 3px;
		        }
				)");
			}
			else
			{
				m_qcombobox_unuse_use_frank_match->setStyleSheet(R"(
		        QComboBox {
		            background-color: green;
		            color: white;
		            border: 1px solid green;
		            border-radius: 3px;
		        }
				)");
			}
		});
		qgridLayout->addWidget(m_qcombobox_unuse_use_frank_match, index, 1);

		index++;
	}
    

	if (camera_index == 14)
    {

        m_function_bottom_match = new DetectionBottomMatch(this, m_qsettings, "m_function_bottom_match",dir);
        m_function_bottom_match->m_image = m_image;

        m_pushbutton_bottom_match = new QPushButton(this);
        m_pushbutton_bottom_match->setFixedSize(control_size);
        m_pushbutton_bottom_match->setText("Bottom Match");
        connect(m_pushbutton_bottom_match, &QPushButton::clicked, this, [=]() {

            if (m_unuse_use_bottom_match == 0)
            {
                QMessageBox::critical(nullptr, "Bottom Match", "OFF ");
                return;
            }
            if (m_image.empty())
            {
                QMessageBox::information(nullptr, "", "no image");
                return;
            }
            QString message;
            m_function_bottom_match->m_image = m_image;
            m_function_bottom_match->showDialog();
            m_function_bottom_match->show();
        });
        qgridLayout->addWidget(m_pushbutton_bottom_match, index, 0);

        m_qcombobox_unuse_use_bottom_match = new QComboBox(this);
        m_qcombobox_unuse_use_bottom_match->setFixedSize(control_size);
        m_qcombobox_unuse_use_bottom_match->addItem("OFF");
        m_qcombobox_unuse_use_bottom_match->addItem("ON");
        qgridLayout->addWidget(m_qcombobox_unuse_use_bottom_match, index, 1);

        index++;
    }
    /*m_qcombobox_save_wrong = new QComboBox(this);
    m_qcombobox_save_wrong->setFixedSize(control_size);
    m_qcombobox_save_wrong->addItem("No Save NG");
    m_qcombobox_save_wrong->addItem("Save NG");
    qgridLayout->addWidget(m_qcombobox_save_wrong, index, 0);*/

    m_qcombobox_save_right = new QComboBox(this);
    m_qcombobox_save_right->setFixedSize(control_size);
    m_qcombobox_save_right->addItem("OK No Save ");
    m_qcombobox_save_right->addItem("OK Save");
    m_qcombobox_save_right->setStyleSheet(R"(
    QComboBox {
        background-color: red;
        color: white;
        border: 1px solid red;
        border-radius: 3px;
    }
    )");
    qgridLayout->addWidget(m_qcombobox_save_right, index, 0);
    connect(m_qcombobox_save_right, &QComboBox::currentTextChanged, this, [=]() {
        if (m_qcombobox_save_right->currentIndex() == 0)
        {
            m_qcombobox_save_right->setStyleSheet(R"(
            QComboBox {
                background-color: red;
                color: white;
                border: 1px solid red;
                border-radius: 3px;
            }
            )");
        }
        else
        {
            m_qcombobox_save_right->setStyleSheet(R"(
            QComboBox {
                background-color: green;
                color: white;
                border: 1px solid green;
                border-radius: 3px;
            }
            )");
        }
    });

//    index++;

    /*m_qcombobox_save_wrong_label = new QComboBox(this);
    m_qcombobox_save_wrong_label->setFixedSize(control_size);
    m_qcombobox_save_wrong_label->addItem("No Save Label NG");
    m_qcombobox_save_wrong_label->addItem("Save Label NG");
    qgridLayout->addWidget(m_qcombobox_save_wrong_label, index, 0);
	index++;*/


//    if (camera_index == 3 || camera_index == 4)
//	{
//		m_qcombobox_save_ai_ng = new QComboBox(this);
//		m_qcombobox_save_ai_ng->setFixedSize(control_size);
//		m_qcombobox_save_ai_ng->addItem("No Save Crop NG");
//		m_qcombobox_save_ai_ng->addItem("Save Crop NG");
//		qgridLayout->addWidget(m_qcombobox_save_ai_ng, index, 0);
		m_qcombobox_save_ai_ok = new QComboBox(this);
		m_qcombobox_save_ai_ok->setFixedSize(control_size);
        m_qcombobox_save_ai_ok->addItem("OK-Croped No Save ");
        m_qcombobox_save_ai_ok->addItem("OK-Croped Save");
        m_qcombobox_save_ai_ok->setStyleSheet(R"(
        QComboBox {
            background-color: red;
            color: white;
            border: 1px solid red;
            border-radius: 3px;
        }
        )");
        connect(m_qcombobox_save_ai_ok, &QComboBox::currentTextChanged, this, [=]() {
            if (m_qcombobox_save_ai_ok->currentIndex() == 0)
            {
                m_qcombobox_save_ai_ok->setStyleSheet(R"(
                QComboBox {
                    background-color: red;
                    color: white;
                    border: 1px solid red;
                    border-radius: 3px;
                }
                )");
            }
            else
            {
                m_qcombobox_save_ai_ok->setStyleSheet(R"(
                QComboBox {
                    background-color: green;
                    color: white;
                    border: 1px solid green;
                    border-radius: 3px;
                }
                )");
            }
        });
        qgridLayout->addWidget(m_qcombobox_save_ai_ok, index, 1);
		index++;
//    }

    m_pushbutton_save_parameter = new QPushButton(this);
    m_pushbutton_save_parameter->setFixedSize(control_size);
    m_pushbutton_save_parameter->setText("Save Para");
    connect(m_pushbutton_save_parameter, &QPushButton::clicked, this, &Function::saveParameter);
    qgridLayout->addWidget(m_pushbutton_save_parameter, index, 0);

    index++;

	m_pushbutton_show_orign_image = new QPushButton(this);
	m_pushbutton_show_orign_image->setFixedSize(control_size);
	m_pushbutton_show_orign_image->setText("Show Orign");
	connect(m_pushbutton_show_orign_image, &QPushButton::clicked, this, [=]() {
		QImage q_image = matToQImage(m_image);
		m_view->setImage(q_image, "");
		return true;
	});
	qgridLayout->addWidget(m_pushbutton_show_orign_image, index, 0);

	m_pushbutton_detection = new QPushButton(this);
	m_pushbutton_detection->setFixedSize(control_size);
	m_pushbutton_detection->setText("Detection");
	
	connect(m_pushbutton_detection, &QPushButton::clicked, this, &Function::detectionImage);
	qgridLayout->addWidget(m_pushbutton_detection, index, 1);
	index++;




	m_qlabel_index = new QLabel();
	m_qlabel_index->setText("Detection Index");
	m_qlabel_index->setFixedSize(control_size);
	qgridLayout->addWidget(m_qlabel_index, index, 0);

	m_qcombobox_index = new QComboBox(this);
	m_qcombobox_index->setFixedSize(control_size);
	for (int i = 0; i < m_dl_times; i++)
	{
		m_qcombobox_index->addItem("Index" + QString::number(i));
	}
	qgridLayout->addWidget(m_qcombobox_index, index, 1);

	if (m_camera_index == 0 || m_camera_index == 1 || m_camera_index == 2)
	{
		m_qlabel_index->setVisible(false);
		m_qcombobox_index->setVisible(false);
	}

	index++;
	
    m_pushbutton_return = new QPushButton(this);
    m_pushbutton_return->setFixedSize(control_size);
    m_pushbutton_return->setText("Exit");
    qgridLayout->addWidget(m_pushbutton_return, index, 0);

	m_pushbutton_on_off = new QPushButton(this);
	m_pushbutton_on_off->setFixedSize(control_size);
	// 使用样式表设置按钮的背景色和前景色
	m_pushbutton_on_off->setStyleSheet("QPushButton {"
		"background-color: green;"  // 设置背景色为红色
		"color: white;"           // 设置文字颜色为白色
		"}");
	m_pushbutton_on_off->setText("ON");
	qgridLayout->addWidget(m_pushbutton_on_off, index, 1);
	connect(m_pushbutton_on_off, &QPushButton::clicked, this, [=]() {
		if (m_on_off)
		{
			m_pushbutton_on_off->setStyleSheet("QPushButton {"
				"background-color: red;"  // 设置背景色为红色
				"color: white;"           // 设置文字颜色为白色
				"}");
			m_pushbutton_on_off->setText("OFF");
			m_on_off = false;
		}
		else
		{
			m_pushbutton_on_off->setStyleSheet("QPushButton {"
				"background-color: green;"  // 设置背景色为红色
				"color: white;"           // 设置文字颜色为白色
				"}");
			m_pushbutton_on_off->setText("ON");
			m_on_off = true;
		}
		return true;
	});

    loadParameter();
    

    path = dir + "/vision_para/" + "camera" + QString::number(m_camera_index) + ".png";


	m_image = imread(path.toLocal8Bit().toStdString(), -1);
	QImage q_image = matToQImage(m_image);
	m_view->setImage(q_image,"");

}

bool Function::detection(HObject image_in, int index,QString& message)
{

	int state;

	if (m_on_off == false)
	{
		return true;
	}

    if (m_unuse_use_width_measure)
    {

//        WriteObject(image_in,std::to_string(m_camera_index).c_str());
        state = m_function_width_measure->detection(image_in, message);
        if (state == false)
        {
            return false;
        }
    }

	
	if (m_unuse_use_dump)
	{
		state = m_function_dump->detection(image_in, message);
		if (state == false)
		{
			return false;
		}
	}
	


    if (m_unuse_use_frank_width)
    {

        state = m_function_frank_width->detection(image_in, message);
        if (state == false)
        {
            return false;
        }
    }
    if (m_unuse_use_frank_match)
    {
        state = m_function_frank_match->detection(image_in, message);
        if (state == false)
        {
            return false;
        }
    }




    if (index == 0)
    {
        if (m_unuse_use_bottom_match)
        {
            state = m_function_bottom_match->detection(image_in, message);
            if (state == false)
            {
                return false;
            }
        }
    }


    if (index == 1)
    {
        if (m_unuse_use_find_shape_model)
        {
            state = m_function_find_shape_model->detection(image_in, message);
            if (state == false)
            {
                return false;
            }
        }
    }


    if (index == 0)
    {
        if (m_unuse_use_circle)
        {
            state = m_function_circle->detection(image_in, message);
            if (state == false)
            {
                return false;
            }
        }
    }

    if (m_unuse_use_segment_sacn)
    {
        state = m_function_segment_sacn->detection(image_in, message);
        image_in = m_function_segment_sacn->image_crop;
        if (state == false)
        {
            return false;
        }
    }

	if (index < m_dl_times)
	{
		if (m_vector_unuse_use_segment_rect.size() > index) {
			if (m_vector_unuse_use_segment_rect[index] && m_vector_segment_rect[index] != nullptr)
			{
				m_vector_segment_rect[index]->detection(image_in, message);
				image_in = m_vector_segment_rect[index]->image_crop;
			}
		}
	}

    if(index<m_dl_times)
    {
		if (m_vector_unuse_use_segment_circle.size() > index) {
			if (m_vector_unuse_use_segment_circle[index] && m_vector_segment_circle[index] != nullptr)
			{
				m_vector_segment_circle[index]->detection(image_in, message);
				image_in = m_vector_segment_circle[index]->image_crop;
			}
		}
    }

    m_image_ai =  himageToMat(image_in);



    if(index<m_dl_times)
    {
        if (m_vector_unuse_use_dl_halcon[index] && m_vector_dl_halcon[index]!=nullptr  )
        {
//            int64 t1 = cv::getTickCount();
            state = m_vector_dl_halcon[index]->detection(image_in, message);
//            int64 t2 = cv::getTickCount();

//            double m_time_use = (t2 - t1) * 1000 / getTickFrequency();
//            logger->info(std::to_string(m_camera_index) + "  camera "+ std::to_string(m_time_use));

            if (state == false)
            {
                return false;
            }
        }
    }


    return true;
}

void Function::detectionImage()
{
    if (m_image.empty())
    {
        QMessageBox::information(nullptr, "", "没有图像");
        return;
    }

    QString message;

    HObject image = matToHImage(m_image);
	
    bool result = detection(image, m_qcombobox_index->currentIndex(),message);
    if(result)
    {
        message += "OK";
    }
    else
    {
        message += "NG";
    }

    Mat image_show;
    draw(m_image, m_qcombobox_index->currentIndex(),image_show);

    QImage q_image = matToQImage(image_show);
    m_view->setImage(q_image, message);
}

void Function::draw(Mat image_in,int index, Mat& image_out)
{
    image_out = image_in.clone();
	if (m_unuse_use_frank_match == 1)
	{
		m_function_frank_match->draw(image_out, image_out);
	}
    if (m_unuse_use_bottom_match == 1)
    {
        m_function_bottom_match->draw(image_out, image_out);
    }
	if (m_unuse_use_dump==1)
	{
		 m_function_dump->draw(image_out, image_out);
	}
	if (m_unuse_use_width_measure == 1)
	{
		m_function_width_measure->draw(image_out, image_out);
	}
    if (m_unuse_use_frank_width == 1)
    {
        m_function_frank_width->draw(image_out, image_out);
    }
    if (m_unuse_use_circle == 1)
    {
        m_function_circle->draw(image_out, image_out);
    }

    if (m_unuse_use_segment_sacn == 1)
    {
        m_function_segment_sacn->draw(image_out, image_out);
    }
    if (m_unuse_use_find_shape_model == 1)
    {
        m_function_find_shape_model->draw(image_out, image_out);
    }


    if (index < m_dl_times)
    {
        if (m_vector_unuse_use_segment_rect.size() > index)
        {
            if (m_vector_unuse_use_segment_rect[index] && m_vector_segment_rect[index] != nullptr)
            {
                m_vector_segment_rect[index]->draw(image_out, image_out);
            }
        }
    }

    if(index<m_dl_times)
    {
        if (m_vector_unuse_use_segment_circle.size() > index)
        {
            if (m_vector_unuse_use_segment_circle[index] && m_vector_segment_circle[index] != nullptr)
            {
                m_vector_segment_circle[index]->draw(image_out, image_out);
            }
        }
    }



    if(index<m_dl_times)
    {
        if (m_vector_unuse_use_dl_halcon[index] && m_vector_dl_halcon[index] != nullptr)
        {
            m_vector_dl_halcon[index]->draw(image_out, image_out);
        }
    }


}

void Function::listViewClick(const QModelIndex& model_index)
{
    QString image_path = model_index.data().toString();

    m_image = imread(image_path.toLocal8Bit().toStdString(), IMREAD_UNCHANGED);

    if (m_image.empty())
    {
        QMessageBox::information(nullptr, "", "load image error");
        return;
    }

    QImage q_image = matToQImage(m_image);
    m_view->setImage(q_image, "");
}

void Function::loadParameter()
{

    try
    {





        for(int i=0;i<m_dl_times;i++)
        {
            m_vector_unuse_use_dl_halcon[i] = m_qsettings->value(m_section + "/" +  "m_vector_unuse_use_dl_halcon"+QString::number(i) ).toInt();
            m_vector_qcombobox_unuse_use_dl_halcon[i]->setCurrentIndex(m_vector_unuse_use_dl_halcon[i]);
            if(m_vector_unuse_use_dl_halcon[i]==1)
            {
                m_vector_dl_halcon[i] = new FunctionDL(this, m_qsettings, "function_dl"+ QString::number(m_camera_index) + QString::number(i), m_camera_index,i);
                m_vector_dl_halcon[i]->loadmodel();
            }
        }

		for (int i = 0; i < m_dl_times; i++)
		{
			if (m_vector_unuse_use_segment_rect.size() > i) {
                m_vector_unuse_use_segment_rect[i] = m_qsettings->value(m_section + "/" + "m_vector_unuse_use_segment_rect" + QString::number(i)).toInt();
				m_vector_qcombobox_unuse_use_segment_rect[i]->setCurrentIndex(m_vector_unuse_use_segment_rect[i]);
			}
		}
        for(int i=0;i<m_dl_times;i++)
        {
			if (m_vector_unuse_use_segment_circle.size() > i) {
                m_vector_unuse_use_segment_circle[i] = m_qsettings->value(m_section + "/" + "m_vector_unuse_use_segment_circle" + QString::number(i)).toInt();
				m_vector_qcombobox_unuse_use_segment_circle[i]->setCurrentIndex(m_vector_unuse_use_segment_circle[i]);
			}
        }
		

        if(m_qcombobox_unuse_use_dump!=nullptr)
        {
            m_unuse_use_dump = m_qsettings->value(m_section + "/" + "m_unuse_use_dump").toInt();
            m_qcombobox_unuse_use_dump->setCurrentIndex(m_unuse_use_dump);
        }

		if (m_function_width_measure != nullptr)
		{
            m_unuse_use_width_measure = m_qsettings->value(m_section + "/" + "m_unuse_use_width_measure").toInt();
			m_qcombobox_unuse_use_width_measure->setCurrentIndex(m_unuse_use_width_measure);
		}

        if (m_function_frank_width != nullptr)
        {
            m_unuse_use_frank_width = m_qsettings->value(m_section + "/" + "m_unuse_use_frank_width").toInt();
            m_qcombobox_unuse_use_frank_width->setCurrentIndex(m_unuse_use_frank_width);
        }

        if (m_function_segment_sacn != nullptr)
        {
            m_unuse_use_segment_sacn = m_qsettings->value(m_section + "/" + "m_unuse_use_segment_sacn").toInt();
            m_qcombobox_unuse_use_segment_sacn->setCurrentIndex(m_unuse_use_segment_sacn);
        }


        if (m_function_circle != nullptr)
        {
            m_unuse_use_circle = m_qsettings->value(m_section + "/" + "m_unuse_use_circle").toInt();
            m_qcombobox_unuse_use_circle->setCurrentIndex(m_unuse_use_circle);
        }




        if (m_function_find_shape_model != nullptr)
        {
            m_unuse_use_find_shape_model = m_qsettings->value(m_section + "/" + "m_unuse_use_find_shape_model").toInt();
            m_qcombobox_unuse_use_find_shape_model->setCurrentIndex(m_unuse_use_find_shape_model);
        }

		if (m_function_frank_match != nullptr)
		{
			m_unuse_use_frank_match = m_qsettings->value(m_section + "/" + "m_unuse_use_frank_match").toInt();
			m_qcombobox_unuse_use_frank_match->setCurrentIndex(m_unuse_use_frank_match);
		}

        if (m_function_bottom_match != nullptr)
        {
            m_unuse_use_bottom_match = m_qsettings->value(m_section + "/" + "m_unuse_use_bottom_match").toInt();
            m_qcombobox_unuse_use_bottom_match->setCurrentIndex(m_unuse_use_bottom_match);
        }
//        if (m_function_segment_circle != nullptr)
//        {
//            m_unuse_use_segment_circle = m_qsettings->value(section + "/" + "m_unuse_use_segment_circle").toInt();
//            m_qcombobox_unuse_use_segment_circle->setCurrentIndex(m_unuse_use_segment_circle);
//        }

        /*m_save_wrong = m_qsettings->value(m_section + "/" + "m_save_wrong").toInt();
        m_save_right = m_qsettings->value(m_section + "/" + "m_save_right").toInt();
        m_save_wrong_label = m_qsettings->value(m_section + "/" + "m_save_wrong_label").toInt();*/
        

       /* m_qcombobox_save_wrong->setCurrentIndex(m_save_wrong);
        m_qcombobox_save_right->setCurrentIndex(m_save_right);
        m_qcombobox_save_wrong_label->setCurrentIndex(m_save_wrong_label);

		if (m_qcombobox_save_ai_ok != nullptr)
		{
			m_save_ai_ok = m_qsettings->value(m_section + "/" + "m_save_ai_ok").toInt();
			m_save_ai_ng = m_qsettings->value(m_section + "/" + "m_save_ai_ng", "").toInt();
			m_qcombobox_save_ai_ok->setCurrentIndex(m_save_ai_ok);
			m_qcombobox_save_ai_ng->setCurrentIndex(m_save_ai_ng);
		}*/

       

    }
    catch (exception& error)
    {
        QMessageBox::critical(nullptr, error.what(), m_section + "para require setting");
    }


    return;
}

void Function::saveParameter()
{
    try
    {
		m_save_right = m_qcombobox_save_right->currentIndex();
		m_save_ai_ok = m_qcombobox_save_ai_ok->currentIndex();


		if (!m_image.empty())
		{
            QString path = m_dir + "/vision_para/" + "camera" + QString::number(m_camera_index) + ".png";
			imwrite(path.toLocal8Bit().toStdString(), m_image);
		}
		



        for(int i=0;i<m_dl_times;i++)
        {

            m_vector_unuse_use_dl_halcon[i] = m_vector_qcombobox_unuse_use_dl_halcon[i]->currentIndex();

        }

        for(int i=0;i<m_dl_times;i++)
        {
			if (m_vector_unuse_use_segment_circle.size() > i) {
				m_vector_unuse_use_segment_circle[i] = m_vector_qcombobox_unuse_use_segment_circle[i]->currentIndex();
			
			}
        }
		for (int i = 0; i < m_dl_times; i++)
		{
			if (m_vector_unuse_use_segment_rect.size() > i) {
				m_vector_unuse_use_segment_rect[i] = m_vector_qcombobox_unuse_use_segment_rect[i]->currentIndex();
			}

		}

        if(m_qcombobox_unuse_use_dump!=nullptr)
        {
            m_unuse_use_dump = m_qcombobox_unuse_use_dump->currentIndex();
            
        }

		if (m_function_width_measure != nullptr)
		{
			m_unuse_use_width_measure = m_qcombobox_unuse_use_width_measure->currentIndex();
			
		}
        if (m_function_frank_width != nullptr)
        {
            m_unuse_use_frank_width = m_qcombobox_unuse_use_frank_width->currentIndex();
            
        }
        if (m_function_circle != nullptr)
        {
            m_unuse_use_circle = m_qcombobox_unuse_use_circle->currentIndex();

        }

        if (m_function_segment_sacn != nullptr)
        {
            m_unuse_use_segment_sacn = m_qcombobox_unuse_use_segment_sacn->currentIndex();

        }

        if (m_function_find_shape_model != nullptr)
        {
            m_unuse_use_find_shape_model = m_qcombobox_unuse_use_find_shape_model->currentIndex();

        }

		if (m_function_frank_match != nullptr)
		{
			m_unuse_use_frank_match = m_qcombobox_unuse_use_frank_match->currentIndex();

		}

        if (m_function_bottom_match != nullptr)
        {
            m_unuse_use_bottom_match = m_qcombobox_unuse_use_bottom_match->currentIndex();

        }
		if (my_para.m_login_privilege >=2)
		{
			for (int i = 0; i < m_dl_times; i++)
			{
				m_qsettings->setValue(m_section + "/" + "m_vector_unuse_use_dl_halcon" + QString::number(i), m_vector_unuse_use_dl_halcon[i]);

			}

			for (int i = 0; i < m_dl_times; i++)
			{
				if (m_vector_unuse_use_segment_circle.size() > i) {
					m_qsettings->setValue(m_section + "/" + "m_vector_unuse_use_segment_circle" + QString::number(i), m_vector_unuse_use_segment_circle[i]);
				}
			}
			for (int i = 0; i < m_dl_times; i++)
			{
				if (m_vector_unuse_use_segment_rect.size() > i) {
					m_qsettings->setValue(m_section + "/" + "m_vector_unuse_use_segment_rect" + QString::number(i), m_vector_unuse_use_segment_rect[i]);
				}

			}

			if (m_qcombobox_unuse_use_dump != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_dump", m_unuse_use_dump);
			}

			if (m_function_width_measure != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_width_measure", m_unuse_use_width_measure);
			}
			if (m_function_frank_width != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_frank_width", m_unuse_use_frank_width);
			}
			if (m_function_circle != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_circle", m_unuse_use_circle);
			}

			if (m_function_segment_sacn != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_segment_sacn", m_unuse_use_segment_sacn);
			}

			if (m_function_find_shape_model != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_find_shape_model", m_unuse_use_find_shape_model);
			}

			if (m_function_frank_match != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_frank_match", m_unuse_use_frank_match);
			}

			if (m_function_bottom_match != nullptr)
			{
				m_qsettings->setValue(m_section + "/" + "m_unuse_use_bottom_match", m_unuse_use_bottom_match);
			}
			
		}



        
		

        /*m_save_wrong = m_qcombobox_save_wrong->currentIndex();
        m_save_right = m_qcombobox_save_right->currentIndex();
        m_save_wrong_label = m_qcombobox_save_wrong_label->currentIndex();*/
        
        
        /*m_qsettings->setValue(m_section + "/" + "m_save_wrong", m_save_wrong);
        m_qsettings->setValue(m_section + "/" + "m_save_right", m_save_right);
        m_qsettings->setValue(m_section + "/" + "m_save_wrong_label", m_save_wrong_label);*/
        

		/*if (m_qcombobox_save_ai_ok != nullptr)
		{
			m_save_ai_ok = m_qcombobox_save_ai_ok->currentIndex();
			m_qsettings->setValue(m_section + "/" + "m_save_ai_ok", m_save_ai_ok);
			m_save_ai_ng = m_qcombobox_save_ai_ng->currentIndex();
			m_qsettings->setValue(m_section + "/" + "m_save_ai_ng", m_save_ai_ng);
		}*/
    }
    catch (exception& error)
    {
        QMessageBox::critical(nullptr, error.what(), m_section + "para require setting");
    }
}

bool Function::showDialog()
{
    return true;
}
